package leetcode;

import java.util.Arrays;

/**
 * 用最少弓箭引爆气球
 */
public class Solution34 {
    class Solution {
        public int findMinArrowShots(int[][] points) {
            //判断异常情况
            if(points.length == 0){
                return 0;
            }
            Arrays.sort(points,(a, b) -> Integer.compare(a[0],b[0]));
            int result  = 1;
            for(int i = 1 ; i < points.length;i++){
                if(points[i][0] > points[i - 1][1]){ //左边界和右边界进行比较
                    result++;
                }else{
                    points[i][1] = Math.min(points[i][1],points[i-1][1]);
                }
            }
            return result;
        }
    }
}
